


import GameData_blxf from "../GameData/GameData";
import { VendorData_blxf } from "../GameData/VendorData";
import { CsvManager_blxf } from "../Manager/CsvManager";
import { EnumManager_blxf } from "../Manager/EnumManager";
import PageManager_blxf from "../Manager/PageManager";
import { PlatformManager_blxf } from "../Manager/PlatformManager";
import { ConfigModule_blxf } from "../Module/ConfigModule";
import { LoadModule_blxf } from "../Module/LoadModule";
import { NumModule_blxf } from "../Module/NumModule";
import PublicModule_blxf from "../Module/PublicModule";
import { UtilsModule_blxf } from "../Module/UtilsModule";

const PageIds: number[] = [ 3, 1, 2 ];

const {ccclass, property} = cc._decorator;

/** 玩法按钮层 */

@ccclass
export class GameBtnList_blxf extends cc.Component {

    @property({ type: [ cc.Node ], tooltip: '按钮分类列表' })
    btnTypeBox: cc.Node[] = [];

    @property({ type: cc.Node, tooltip: '通用按钮盒子' })
    commonBox: cc.Node = null;

    @property({ type: cc.Node, tooltip: '箭头_左' })
    leftBtn: cc.Node = null;

    @property({ type: cc.Node, tooltip: '箭头_右' })
    rightBtn: cc.Node = null;

    @property({ type: cc.Node, tooltip: '退出按钮' })
    backBtn: cc.Node = null;

    @property({ type: cc.Node, tooltip: '房间按钮盒子' })
    roomBox: cc.Node = null;


    @property({ type: cc.Node, tooltip: '客源' })
    guestBooksNode: cc.Node = null;

    @property({ type: cc.Node, tooltip: '进货榜' })
    shopRankNode: cc.Node = null;

    @property({ type: cc.Node, tooltip: '财富帮' })
    wealthBtnNode: cc.Node = null;

    @property({ type: cc.Node, tooltip: '春联' })
    coupletNode: cc.Node = null;

    @property({ type: cc.Node, tooltip: '爱心' })
    loveNumNode: cc.Node = null;

    @property({ type: cc.Node, tooltip: '上货按钮' })
    addShopBtn: cc.Node = null;

    @property({ type: cc.Node, tooltip: '卸货整理按钮' })
    removeRetartBtn: cc.Node = null;

    @property({ type: cc.Button, tooltip: '送货按钮置灰图片' })
    removeRestartImg: cc.Button = null;

    @property({ type: cc.Node, tooltip: '粒子1' })
    particleNode1: cc.Node = null;

    @property({ type: cc.Node, tooltip: '粒子2' })
    particleNode2: cc.Node = null;


    @property({ type: cc.Node, tooltip: '新商品图标' })
    newShopTips: cc.Node = null;

    @property({ type: cc.Node, tooltip: '新客人图标' })
    newGuestTips: cc.Node = null;

    @property({ type: cc.Node, tooltip: '新对联图标' })
    newCoupletTips: cc.Node = null;


    @property({ type: cc.Node, tooltip: '收益双倍动画' })
    rewardSpineNode: cc.Node = null;

    @property({ type: cc.Node, tooltip: '收益双倍时间' })
    rewardTimeNode: cc.Node = null;

    @property({ type: cc.Node, tooltip: '速度双倍动画' })
    speedSpineNode: cc.Node = null;

    @property({ type: cc.Node, tooltip: '速度双倍时间' })
    speedTimeNode: cc.Node = null;

    @property({ type: cc.Node, tooltip: '新库存' })
    newNumTips: cc.Node = null;

    @property({ type: cc.Node, tooltip: '可解锁或升级' })
    newLevelTips: cc.Node = null;

    @property({ type: cc.Node, tooltip: '解锁装饰提示' })
    newBuildTips: cc.Node = null;

    @property({ type: cc.Node, tooltip: '房间解锁装饰提示' })
    newRoomBuildTips: cc.Node = null;


    @property({ type: cc.Node, tooltip: '补货弱引导动画' })
    addShopHandAnimationNode: cc.Node = null;

    @property({ type: cc.Node, tooltip: '手指节点' })
    handNode: cc.Node = null;

    @property({ tooltip: '手指动画' })
    _handTween: cc.Tween = null;


    @property({ tooltip: '右侧按钮动画' })
    _rightBtnSkeleton: sp.Skeleton|boolean = null;

    @property({ tooltip: '左侧按钮动画' })
    _leftBtnSkeleton: sp.Skeleton|boolean = null;

    _isClick: boolean = false;

    @property({ tooltip: '运行帧数' })
    _dtNum: number = 0;

    @property({ tooltip: '微信授权按钮' })
    _btnAuthorize: any = null;

    @property({ tooltip: '页面动画' })
    _pageTween: cc.Tween = null;

    @property({ tooltip: '是否显示卸货整理按钮' })
    _isRemoveRestartBtn: boolean = false;

    @property({ tooltip: '卸货整理按钮动画' })
    _removeRestartBtnTween: cc.Tween = null;


    // LIFE-CYCLE CALLBACKS:

    onLoad () {
        this._isRemoveRestartBtn = false;

        cc.game.on('onTouchRestartShop_blxf', this.onTouchRestartShop, this);
        cc.game.on('onTouchRemoveShop_blxf', this.onTouchRemoveShop, this);

        cc.game.on('onGameBtnPos_blxf', this.onBtnPos_blxf, this);
        cc.game.on('onUpdateBtnAuthorize_blxf', this.onUpdateBtnAuthorize_blxf, this);

        cc.game.on('loadLoveParticle_blxf', this.loadLoveParticle_blxf, this);
        cc.game.on('initIconPosition_blxf', this.initIconPosition_blxf, this);

        cc.game.on('onAddShopBtnPos_blxf', this.onAddShopBtnPos_blxf, this);

        cc.game.on('onTouchAutoPlayerBtn', this.onTouchAutoPlayerBtn, this);

        cc.game.on('onUpdatePage_blxf', this.onUpdatePage_blxf, this);

        cc.game.on('onTouchLeft', this.onTouchLeft, this);
        cc.game.on('updateBtns_blxf', this.updateBtns_blxf, this);
    }

    start () {
        this.initBtn_blxf();
        this.updateBtns_blxf();

        this.updateLoveNum_blxf();
    }

    onDestroy () { cc.game.removeAll(this) }

    update ( dt: number ) {
        this._dtNum += 1;

        // PublicModule_blxf.onUpdateBuffTime_blxf( dt );
        // PublicModule_blxf.onUpdateLeaveMainPlayTime_blxf( dt );

        // this._dtNum % 60 == 1 && PublicModule_blxf.onCheckNegativeBuff_blxf();

        // this._dtNum % 60 == 2 && PageManager_blxf.instance.onCheckPageList_blxf();
        
        // PublicModule_blxf.onLeftTipsTimeTimer_blxf( dt );
        // PublicModule_blxf.onRightTipsTimeTimer_blxf( dt );

        // this._dtNum % 10 == 1 && this.updateDoubleTime_blxf( dt );
        // this._dtNum % 10 == 2 && this.updateCoupletBtn_blxf();

        // this._dtNum % 10 == 8 && this.onCheckBuyShopBtnImg_blxf();
        // this._dtNum % 10 == 9 && this.onCheckRemoveRestartBtn_blxf();

        // if ( PublicModule_blxf.isMoveAnimation ) return;

        // this._dtNum % 10 == 0 && this.onCheckNewGuest_blxf();
        // this._dtNum % 10 == 1 && this.onCheckNewShop_blxf();
        // this._dtNum % 10 == 2 && this.onCheckNewCouplet_blxf();
        // this._dtNum % 10 == 3 && this.onCheckNullVendor_blxf();
        // this._dtNum % 100 == 1 && this.onCheckNewLevel_blxf();
        // this._dtNum % 100 == 2 && this.onCheckNewBuild_blxf( 1 );
        // this._dtNum % 100 == 3 && this.onCheckNewBuild_blxf( 2 );
        // this._dtNum % 100 == 4 && this.loadBtnTipsSpine_blxf( 1 );
        // this._dtNum % 100 == 5 && this.loadBtnTipsSpine_blxf( 2 );

        // this._dtNum % 10 == 4 && this.onCheckHandAnimation_blxf();
    }

    initIconPosition_blxf () {
        PublicModule_blxf.coupletPos = UtilsModule_blxf.instance.getCanvasPos_blxf( this.coupletNode );
    }

    initBtn_blxf () {
        UtilsModule_blxf.instance.setNodeSize_blxf( this.node );

        PublicModule_blxf.coupletParentList[0] = this.coupletNode.parent;

        let { checkH, isIpad, winSizeW } = ConfigModule_blxf.instance;
        this.btnTypeBox.forEach( item =>{
            item.children.forEach( btnItem =>{
                let _isGT: boolean = btnItem.y > 0;
                let _updateY: number = _isGT ? checkH / 2 : -checkH;
                btnItem.y += _updateY;
            })
        })

        if ( isIpad ) this.node.width = winSizeW;

        this.backBtn.y += checkH;
        this.shopRankNode.y += checkH / 2;
        this.guestBooksNode.y += checkH / 2;
        this.wealthBtnNode.y += checkH / 2;
        this.leftBtn.y -= checkH * 3 / 4;
        this.rightBtn.y -= checkH * 3 / 4;

        // PlatformManager_blxf.instance.createAuthorizeBtn_blxf(
        //     1, this.wealthBtnNode,
        //     ( btnAuthorize: any )=>{
        //         this._btnAuthorize = btnAuthorize;

        //         this.onUpdateBtnAuthorize_blxf( false );
        //     },
        //     // 点击授权按钮回调
        //     ( isAuthorize: boolean ) =>{
        //         // if ( isAuthorize ) {
        //             this.onTouchWealth();

        //             // let _shopIdList: number[] = GameData_blxf.instance.getShopIdList_blxf();
        //             // OpenDataContext_blxf.setShopNum_blxf( _shopIdList.length );
        //         // }
        //     }
        // )
    }

    /**
     * 更新授权按钮显隐
     * @param isShow 是否显示授权按钮
     */
    onUpdateBtnAuthorize_blxf ( isShow: boolean = false ) {
        if ( !this._btnAuthorize ) return;

        if ( isShow ) this._btnAuthorize.show();
        if ( !isShow ) this._btnAuthorize.hide();
    }

    /** 切换按钮显示 */
    updateBtns_blxf () {
        // let _isTween: boolean = !!PublicModule_blxf.pageTween;
        // let _isPlay1: boolean = PublicModule_blxf.gamePlayPageId == 1;
        // let _isPlay2: boolean = PublicModule_blxf.gamePlayPageId == 2;
        // let _isPlay3: boolean = PublicModule_blxf.gamePlayPageId == 3 || PublicModule_blxf.gamePlayPageId == 5;
        // let _isPlay4: boolean = PublicModule_blxf.gamePlayPageId == 4;
        // let _isPlay5: boolean = PublicModule_blxf.gamePlayPageId == 5;
        // let _isTouchRoom: boolean = !PublicModule_blxf.isTouchRoomBtn && ( _isPlay3 || _isPlay5 );
        // let _isLeft : boolean = (_isPlay2 || _isPlay1) && !_isTween;
        // let _isRight: boolean = (_isPlay1 || _isTouchRoom /*|| _isPlay3*/) && !_isTween;

        // this.leftBtn.active  = _isLeft;
        // this.rightBtn.active = _isRight;
        // // this.leftBtn.active  = _isPlay2;
        // // this.rightBtn.active = _isPlay1;

        // this.roomBox.active = _isPlay3;

        // this.commonBox.active = !_isPlay4 && !PublicModule_blxf.isJengaGame;

        // this.btnTypeBox.forEach( ( btnBoxItem, index ) =>{
        //     let _isBtn1: boolean = index == 0 && _isPlay1 && !_isTween;
        //     let _isBtn2: boolean = index == 1 && _isPlay2 && !_isTween;
        //     let _isBtn3: boolean = index == 2 && _isPlay3 && !_isTween;
        //     btnBoxItem.active = _isBtn1 || _isBtn2 || _isBtn3;
        // })
    }

    /** 切换页面 */
    onUpdatePage_blxf () {
        if ( PublicModule_blxf.gamePlayPageId == 1 ) return;

        PageManager_blxf.instance.onOffAllPanel_blxf();
        
        PublicModule_blxf.gamePlayPageId == 2 && this.onTouchLeft();
        PublicModule_blxf.gamePlayPageId == 3 && this.onTouchRight();
    }

    /** 点击左侧箭头按钮 */
    onTouchLeft ( e: any = undefined ) {
        if ( PublicModule_blxf.isGui ) return;

        let _isEvent: boolean = e === true;
        
        let _isJumpJenga: boolean = e && !_isEvent && PublicModule_blxf.gamePlayPageId == 1;
        if ( _isJumpJenga ) return this.onJumpToJenga();

        this.onChangePage_blxf( -1, _isEvent );

        if ( PublicModule_blxf.gamePlayPageId != 3 ) return;

        this.onCheckNewBuild_blxf( 2, true );
        this.onCheckTriggeGuidanceRoomBuild_blxf();

        // 重置时间
        let _isInit: boolean = this.newRoomBuildTips.opacity == 255;
        _isInit && PublicModule_blxf.onInitLeftTipsTime_blxf();

        this.loadBtnTipsSpine_blxf( 2 );

        this.scheduleOnce(()=>{
            cc.game.emit('onUpdateTopNum_blxf');
        })
    }

    /** 点击右侧箭头按钮 */
    onTouchRight ( e: any = undefined ) {
        if ( PublicModule_blxf.isGui ) return;

        // 房间跳转到食堂
        let _isRoom: boolean = e && [ 3, 5 ].includes( PublicModule_blxf.gamePlayPageId );
        if ( _isRoom ) return this.onJumpToJenga();

        this.onChangePage_blxf( 1 );

        if ( PublicModule_blxf.gamePlayPageId != 2 ) return;

        // 检测触发引导
        this.onCheckNewBuild_blxf( 1, true );
        this.onCheckTriggeGuidanceBuild_blxf();

        // 重置时间
        let _isInit: boolean = this.newBuildTips.opacity == 255;
        _isInit && PublicModule_blxf.onInitRightTipsTime_blxf();

        this.loadBtnTipsSpine_blxf( 1 );

        // // 上报自定义事件
        // this.onReportEvent_blxf();

        // 更新自动售卖金币、财富
        cc.game.emit('onUpdateTopNum_blxf');
        // 更新自动售卖收益
        cc.game.emit('updateSaleRewardNum_blxf');

        let _isAddShop: boolean = this.onCheckIsAddShop_blxf();
        PublicModule_blxf.isAutoSaleNeedAddShop = _isAddShop;
        cc.game.emit('onBossDialogue_blxf', _isAddShop);
    }

    /** 房间跳转到食堂 */
    onJumpToJenga () {
        UtilsModule_blxf.instance.loadBundPanel_blxf( 2, ()=>{
            cc.game.emit('onCloseVendorPanel');
            cc.game.emit('updateBtns_blxf');

            cc.game.emit('onUpdateGamePlayPage_blxf', true);
        });
    }

    /**
     * 切换页面
     * @param pageId 页面id 
     */
    onChangePage_blxf ( updatePageIndex: number, isEvent: boolean = false ) {
        if ( PublicModule_blxf.pageTween ) return;

        let _oldIndex: number = PageIds.indexOf( PublicModule_blxf.gamePlayPageId );
        let _newIndex: number = _oldIndex + updatePageIndex;
        let pageId: number = PageIds[ _newIndex ];
        if ( pageId === undefined ) return;

        if ( PublicModule_blxf.gamePlayPageId == pageId ) return;
        let _isCheck: boolean = pageId == 3 || PublicModule_blxf.gamePlayPageId == 3;
        PublicModule_blxf.gamePlayPageId = pageId;

        // 检测触发离开主玩法生气表情
        pageId == 1 && this.onCheckLeaveMainPlayTime_blxf();

        let { winSizeW } = ConfigModule_blxf.instance;
        let _t = isEvent ? 0 : 0.5;
        let _updateX: number = winSizeW * (_newIndex - 1) * -1;
        if ( _isCheck ) _updateX = 0;
        let _pageBox: cc.Node = PublicModule_blxf.gamePlayParentNode;

        PublicModule_blxf.pageTween = cc.tween( _pageBox )
        .call(()=>{
            this.updateBtns_blxf();
        })
        .to( _t, { x: _updateX }, cc.easeSineInOut())
        .call(()=>{
            PublicModule_blxf.pageTween = null;
            this.updateBtns_blxf();
        })
        .start();
    }

    /** 检测触发离开主玩法生气表情 */
    onCheckLeaveMainPlayTime_blxf () {
        let _isCheck: boolean = PublicModule_blxf.onCheckLeaveMainPlayTime_blxf();
        if ( !_isCheck ) return;

        let { DIALOGUE_ANGRY } = EnumManager_blxf.guestDialogueType;
        cc.game.emit('onUpateGuestAnimation_blxf', DIALOGUE_ANGRY);
    }

    /** 更新爱心值 */
    updateLoveNum_blxf () {
        let _addLoveNum: number = GameData_blxf.instance.getAddLoveNum_blxf();
        UtilsModule_blxf.setText_blxf( this.loveNumNode, `${ _addLoveNum }`);
    }

    /** 上货 */
    onTouchAddShop () {
        if ( PublicModule_blxf.isAddShopAnimation ) return;
        
        cc.game.emit('onAddVendorShopList');

        PublicModule_blxf.onUpdateBuffNum_blxf();
    }

    /** 重装 */
    onTouchRestartShop ( e: cc.Event.EventTouch ) {
        if ( !e ) return this.onRestartShop_blxf( e );

        PlatformManager_blxf.instance.onPlayVideo_blxf(()=>{
            this.onRestartShop_blxf( e );
        })

        // UtilsModule_blxf.onReportEvent_blxf( 2, 110, true );
    }

    /** 触发重装逻辑 */
    onRestartShop_blxf ( e ) {
        let _timer: number = e ? 0 : 0.05;
        this.scheduleOnce(()=>{
            VendorData_blxf.instance.onRestartVendorShop_blxf();

            this.scheduleOnce(()=>{
                cc.game.emit('onRemoveVendorAllShop');
            }, 0.05)
        }, _timer)
    }

    /** 卸货 */
    onTouchRemoveShop ( e: cc.Event.EventTouch ) {
        if ( !e ) return this.onRemoveShop_blxf( e );

        PlatformManager_blxf.instance.onPlayVideo_blxf(()=>{
            this.onRemoveShop_blxf( e );
        })

        // UtilsModule_blxf.onReportEvent_blxf( 2, 111, true );
    }

    /** 送货 */
    onTouchBuyShop_blxf () {
        cc.game.emit('onBuyAllMoveShop_blxf');
    }

    /** 卸货整理 */
    onTouchRemoveStartShop_blxf () {
        PlatformManager_blxf.instance.onPlayVideo_blxf(()=>{
            // this.onTouchRemoveShop( null );
            this.onTouchRestartShop( null );
        })

        // // 上报自定义事件
        // UtilsModule_blxf.onReportEvent_blxf( 2, 121, true );
    }

    /** 触发卸货逻辑 */
    onRemoveShop_blxf ( e: cc.Event.EventTouch ) {
        VendorData_blxf.instance.initIntShopData_blxf();
        VendorData_blxf.instance.initVendorMarkRemove_blxf();
        VendorData_blxf.instance.onRemoveVendorShop_blxf(0, !!e);

        e && cc.game.emit('onRemoveVendorAllShop', true);
    }

    /** 离开 */
    onTouchClose () {
        if ( PublicModule_blxf.isJengaGame ) {
            cc.game.emit('onUpdatePage_blxf');
            cc.game.emit('onUpdateGamePlayPage_blxf', true);
            return;
        }

        if ( [ 3, 5 ].includes( PublicModule_blxf.gamePlayPageId) ) {
            PublicModule_blxf.isTouchRoomBtn = false;
        }

        let _isTouch: boolean = PublicModule_blxf.gamePlayPageId == 1;
        cc.game.emit('onCloseVendorPanel', _isTouch);
    }

    /** 财富榜 */
    onTouchWealth () { 

    }
    
    /** 客源 */
    onTouchGuestBooks () {
        // PageManager_blxf.instance.loadVendorLvUpPanel_blxf();
        // return;

        let _guestList: any[] = VendorData_blxf.instance.getGuestInfo_blxf();
        let _options: object = { guestList: _guestList };
        PageManager_blxf.instance.loadGuestBooksPanel_blxf( _options );
    }

    /** 进货榜 */
    onTouchShopRank () {
        // UtilsModule_blxf.onTips_blxf( '暂未开放' );
        return this.loadShopRankPanel_blxf();

        // if ( this._isClick ) return;
        // UtilsModule_blxf.instance.setClick_blxf( this );

        // let _isTT: boolean = ConfigModule_blxf.isTtPlatform_blxf();
        // if ( !_isTT || PublicModule_blxf.isLogin || cc.sys.isBrowser ) return this.loadShopRankPanel_blxf();

        // PlatformManager_blxf.instance.login_blxf( ( isOk: boolean )=>{
        //     if ( !isOk ) return;

        //     PublicModule_blxf.isLogin = true;

        //     window['tt'].getUserInfo({
        //         // withCredentials: true,
        //         // withRealNameAuthenticationInfo: true,
        //         success (res) {
        //             console.log(`getUserInfo 调用成功`, res.userInfo);
        //         },
        //         fail (res) {
        //             console.log(`getUserInfo 调用失败`, res.errMsg);
        //         },
        //     });

        //     this.loadShopRankPanel_blxf();
        // })
    }

    // 加载进货榜
    loadShopRankPanel_blxf () {
        PageManager_blxf.instance.loadShopRankPanel_blxf();

        UtilsModule_blxf.onReportEvent_blxf( 2, 332 );
    }

    // 加载公益
    onTouchLovePanel () {
        let _loveNum: number = GameData_blxf.instance.getAddLoveNum_blxf();
        let _options: any = { loveNum: _loveNum };
        PageManager_blxf.instance.loadLovePanel_blxf( _options );

        UtilsModule_blxf.onReportEvent_blxf( 2, 334 );
    }

    /** 加载对联 */
    onTouchCoupletPanel () {
        PageManager_blxf.instance.loadCoupletPanel_blxf();

        UtilsModule_blxf.onReportEvent_blxf( 2, 335 );
    }

    /** 点击自动售卖玩法按钮 */
    onTouchAutoPlayerBtn ( e: cc.Event.EventTouch, btnType: string ) {
        if ( this._isClick ) return;
        UtilsModule_blxf.instance.setClick_blxf( this );

        // cc.log('onTouchAutoPlayerBtn >>', btnType);
        switch ( btnType ) {
            case '11' : this.loadLevelUpPanel_blxf(); break;
            case '12' : this.loadBuildPanel_blxf( 1 ); break;
            case '21' : this.loadDoubleRewardPanel_blxf(); break;
            case '22' : this.loadAddSpeedSalePanel_blxf(); break;
            case '31' : this.loadLookPanel_blxf(); break;
        }
    }

    /** 升级 */
    loadLevelUpPanel_blxf () {
        PageManager_blxf.instance.loadLevelUpPanel_blxf();
    }

    /** 装修 */
    loadBuildPanel_blxf ( panelType ) {
        // PageManager_blxf.instance.loadRenovationPanel_blxf( panelType );
    }

    /** 收益双倍 */
    loadDoubleRewardPanel_blxf () {
        PageManager_blxf.instance.loadCommonVendorPanel_blxf({ type: 7 });
    }

    /** 加速售卖 */
    loadAddSpeedSalePanel_blxf () {
        // PageManager_blxf.instance.loadCommonVendorPanel_blxf({ type: 8 });
    }

    /** 查看库存 */
    loadLookPanel_blxf () {
        PageManager_blxf.instance.loadLookPanel_blxf();

        PublicModule_blxf.isAutoSaleNeedAddShop && GameData_blxf.instance.setIsGuidanceAddShop_blxf();
        PublicModule_blxf.isAutoSaleNeedAddShop = false;
    }


    /** 装修(房间内部) */
    onTouchRoomBuildPanel () {
        let _panelType = 2;
        switch ( PublicModule_blxf.gamePlayPageId ) {
            case 5: _panelType = 3;
        }
        this.loadBuildPanel_blxf( _panelType );
    }

    

    /**
     * 按钮类型
     * @param btnType 1: 客人图鉴、2: 进货榜 
     * @param cb 回调函数
     */
    onBtnPos_blxf ( btnType: number, cb: any ) {
        let _btnPos: cc.Vec3;

        switch ( btnType ) {
            // case 1: _btnPos = this.guestBooksNode.position; break;
            case 1: _btnPos = this.shopRankNode.position; break;
            case 2: _btnPos = this.shopRankNode.position; break;
        }

        cb && cb( _btnPos );
    }


    /**
     * 加载爱心粒子特效
     * @param startPos 起始坐标
     */
    loadLoveParticle_blxf ( startPos: cc.Vec3 ) {
        let _endPos: cc.Vec3 = UtilsModule_blxf.instance.getCanvasPos_blxf( this.loveNumNode );

        let _t1 = 0.7 * 2, _t2 = 2, _endX: number = _endPos.x, _endY: number = _endPos.y;
        this.particleNode1.active = true;
        this.particleNode1.position = startPos;
        this.particleNode1.position = startPos;

        this.onBezierTo( this.particleNode1, _endPos, _t1, ()=>{
            this.particleNode1.x = -1000;
            let newParticleNode2 = LoadModule_blxf.instance.LoadNode_blxf({
                prefabNode: this.particleNode2, parentNode: this.particleNode2.parent
            })
            newParticleNode2.active = true;
            cc.tween( this.particleNode2 ).delay( _t2 ).call(()=>{
                this.particleNode1.active = false;
                newParticleNode2.destroy();
            }).start();

            this.updateLoveNum_blxf();
        });
    }

    /**
     * 加载两侧按钮动画
     * @param loadType 1：右侧、2：左侧
     */
    loadBtnTipsSpine_blxf ( loadType: number = 1 ) {
        let _btnNode: cc.Node = loadType == 1 ? this.rightBtn : this.leftBtn;
        let _skeletonName: string = loadType == 1 ? '_rightBtnSkeleton' : '_leftBtnSkeleton';
        let _tipsNode: cc.Node = loadType == 1 ? this.newBuildTips : this.newRoomBuildTips;
        let _tipsTime: number = loadType == 1 ? PublicModule_blxf.rightTipsTime : PublicModule_blxf.leftTipsTime;

        let _iconNode: cc.Node = _btnNode.children[0];

        let _isHide: boolean = _tipsTime > 0;
        _isHide = _isHide || PublicModule_blxf.gamePlayPageId != 1 || loadType == 2;
        if ( _tipsNode.opacity != 255 || _isHide ) {
            _iconNode.opacity = 255;
            if ( this[_skeletonName] && this[_skeletonName]['node'] ) {
                this[_skeletonName]['node'].destroy();
                this[_skeletonName] = null;
            }
            return;
        }

        if ( _isHide ) return;

        if ( this[_skeletonName] ) return;
        this[_skeletonName] = true;

        let { SPINE_AUTO_RIGHT_ICON, SPINE_AUTO_LEFT_ICON } = EnumManager_blxf.gameSpineType;
        let _spineId: string = loadType == 1 ? SPINE_AUTO_RIGHT_ICON : SPINE_AUTO_LEFT_ICON;
        UtilsModule_blxf.instance.createSpine_blxf( _spineId, _btnNode, ( skeleton: sp.Skeleton) =>{
            this[_skeletonName] = skeleton;
            this[_skeletonName].node.scale = 0.8;
            this[_skeletonName].node.scaleX = loadType == 1 ? 1 : -1;
            _iconNode.opacity = 0;
        })
    }

    /**
     * 贝塞尔曲线
     * @param {*} tweenNode 动画节点
     * @param {*} targetPos 终点坐标
     * @param {*} bezierTime 动画时间
     */
    onBezierTo (tweenNode, targetPos, bezierTime = 1, cb: any) {
        var _x1, _y1, _x2, _y2, _x3, _y3, _startPos, _bezier;
        _startPos = cc.v2(tweenNode.x, tweenNode.y);
        var { x: _x1, y: _y1 } = _startPos;
        var { x: _x3, y: _y3 } = targetPos;
        _x2 = (_x3 + _x1) * 0.8, _y2 = (_y3 + _y1) / 2;
        // cc.log('onBezierTo ==>>>', _x1, _y1, _x2, _y2, _x3, _y3);
        _bezier = [cc.v3(_x1, _y1), cc.v3(_x2, _y2), cc.v3(_x3, _y3)];
        cc.tween(tweenNode).bezierTo(bezierTime, _bezier[0], _bezier[1], _bezier[2])
        .call(()=>{
            cb && cb();
        })
        .start();
    }

    /** 不可送货时按钮置灰 */
    onCheckBuyShopBtnImg_blxf () {
        let _list: number[] = VendorData_blxf.instance.getVendorAllShopIdList_blxf( -1, false, true );
        let _isCheck: boolean = _list.length == 0;
        this.removeRestartImg.interactable = !_isCheck;
        this.removeRestartImg.node.active = _isCheck;
    }

    /** 检测卸货重装按钮显隐 */
    onCheckRemoveRestartBtn_blxf () {
        let _isShow: boolean = this.removeRestartImg.node.active;
        let _isCheck: boolean = VendorData_blxf.instance.onCheckVendorShopNum_blxf( 2 );
        let _isActive: boolean = _isCheck && _isShow;
        this.removeRetartBtn.active = _isActive;

        if ( _isActive && !this._isRemoveRestartBtn ) {
            // // 上报自定义事件
            // this._dtNum > 60 && UtilsModule_blxf.onReportEvent_blxf( 2, 120, true );

        }
        this._isRemoveRestartBtn = _isActive;

        // 晃动动画
        UtilsModule_blxf.instance.onIconTween( this, _isActive, this.removeRetartBtn, '_removeRestartBtnTween' );
    }
    
    /** 检测是否有新商品未查看 */
    onCheckNewShop_blxf () {
        let _shopList: any[] = GameData_blxf.instance.getShopList_blxf();
        let _isNew: boolean = !!_shopList.find( item => item.isNew );
        this.newShopTips.opacity = _isNew ? 255 : 0;
    }

    /** 检测是否有新商品未查看 */
    onCheckNewGuest_blxf () {
        let _guestList: any[] = GameData_blxf.instance.getGuestList_blxf();
        let _isNew: boolean = !!_guestList.find( item => {
            let _isCheck: boolean = GameData_blxf.instance.onCheckGuestId_blxf( item.guestId );
            return item.isNew && _isCheck;
        });
        if ( !_isNew ) {
            let { receivePaperNum } = UtilsModule_blxf.instance.onCheckCollectPaperInfo( 2 );
            _isNew = receivePaperNum > 0;
        }
        if ( !_isNew ) {
            let { receivePaperNum } = UtilsModule_blxf.instance.onCheckCollectPaperInfo( 3 );
            _isNew = receivePaperNum > 0;
        }
        this.newGuestTips.opacity = _isNew ? 255 : 0;
    }

    /** 检测是否有新对联未查看 */
    onCheckNewCouplet_blxf () {
        let _isNew: boolean = false;

        let _coupletList: any[] = GameData_blxf.instance.getCoupletList_blxf();
        _coupletList.forEach( coupletItem =>{
            if ( _isNew ) return;
            if ( !coupletItem.isNew ) return;

            _isNew = true;
        })

        this.newCoupletTips.opacity = _isNew ? 255 : 0;
    }

    /** 检测是否有菜摊库存为零 */
    onCheckNullVendor_blxf () {
        let _isNull: boolean = false;

        let _autoVendorList: any = GameData_blxf.instance.getAutoVendorData_blxf();
        _autoVendorList.forEach( item =>{
            if ( _isNull ) return;
            if ( item.autoShopNum > 0 ) return;
            _isNull = true;
        })

        this.newNumTips.opacity = _isNull ? 255 : 0;
    }

    /** 检测自动售卖解锁或升级 */
    onCheckNewLevel_blxf () {
        let _isNew: boolean;

        let _dataList: any[] = CsvManager_blxf.instance.getVendorAndTargetData_blxf();
        _dataList.forEach( item =>{
            if ( _isNew ) return;

            let { isUnlock, isCondition, isConsume } = item;
            _isNew = isCondition && isConsume;
        })

        this.newLevelTips.opacity = _isNew ? 255 : 0;
    }

    /**
     * 检测解锁装饰
     * @param checkType 1自动售卖装饰、2房间内部装饰 
     */
    onCheckNewBuild_blxf ( checkType: number = 1, isTouch: boolean = false ) {
        if ( !isTouch && checkType == 1 && PublicModule_blxf.gamePlayPageId != 2 ) return;
        if ( !isTouch && checkType == 2 && ![ 3, 4, 5 ].includes( PublicModule_blxf.gamePlayPageId ) ) return;

        if ( checkType == 2 ) {
            if ( PublicModule_blxf.gamePlayPageId == 5 ) {
                checkType = 3;
            }
        }

        let _isNew: boolean = UtilsModule_blxf.onCheckNewBuildTips_blxf( checkType );

        switch ( checkType ) {
            case 1 : this.newBuildTips.opacity = _isNew ? 255 : 0;     break;
            case 2 :
            case 3 : this.newRoomBuildTips.opacity = _isNew ? 255 : 0; break;
        }
    }

    /** 检测是否需要补货 */
    onCheckIsAddShop_blxf () {
        let _isCheck: boolean = true;
        let _isUnlockVendor: boolean = false;

        let _vendorDataList: any[] = CsvManager_blxf.instance.getVendorAndTargetData_blxf( 1 );
        _vendorDataList.forEach( itemData =>{
            if ( !_isCheck ) return;
            let { _isUnlock, data } = itemData;
            if ( !_isUnlock ) return;

            _isUnlockVendor = true;

            let { autoShopNum } = data;
            if ( autoShopNum != 0 ) _isCheck = false;
        })

        return _isCheck && _isUnlockVendor;
    }

    /** 检测是否触发自动售卖补货弱引导 */
    onCheckHandAnimation_blxf () {
        if ( !this.addShopHandAnimationNode ) return;

        let _isGuidanceAddShop: boolean = GameData_blxf.instance.getIsGuidanceAddShop_blxf();
        if ( _isGuidanceAddShop ) {
            this.addShopHandAnimationNode.destroy();
            this.addShopHandAnimationNode = null;
            return;
        }

        let _isHand: boolean = PublicModule_blxf.isAutoSaleNeedAddShop;
        this.addShopHandAnimationNode.active = _isHand;
        _isHand && this.onHandAnimation_blxf();

        if ( !_isHand ) {
            this._handTween && this._handTween.stop();
            this._handTween = null;
        }
    }

    /** 手指动画 */
    onHandAnimation_blxf () {
        if ( this._handTween ) return;

        let _t1 = 0.4, _t2 = 0.4;
        let _scale1 = 0.85, _scale2 = 1;
        let _tween = cc.tween( this.handNode )
        .to(_t1, { scale: _scale1 })
        .to(_t2, { scale: _scale2 })

        this.handNode.scale = 1;
        this._handTween = cc.tween( this.handNode ).repeatForever( _tween ).start();
    }

    onAddShopBtnPos_blxf ( cb: any ) {
        cb && cb( this.addShopBtn.position );
    }


    /** 更新双倍增益剩余时间 */
    updateDoubleTime_blxf ( dt: number ) {
        let _isDoubleSpeed : boolean = UtilsModule_blxf.isDoubleSpeedTime_blxf();
        let _isDoubleReward: boolean = UtilsModule_blxf.isDoubleRewardTime_blxf();

        this.speedSpineNode.active = _isDoubleSpeed;
        this.rewardSpineNode.active = _isDoubleReward;

        if ( _isDoubleSpeed ) {
            let _doubleSpeedTime : number = GameData_blxf.instance.getAutoDoubleSpeedTime_blxf();
            let _timeStr1: string = NumModule_blxf.instance.getTimeStr2_blxf( _doubleSpeedTime );
            UtilsModule_blxf.setText_blxf( this.speedTimeNode, _timeStr1 );
        }

        if ( _isDoubleReward ) {
            let _doubleRewardTime: number = GameData_blxf.instance.getAutoDoubleRewardTime_blxf();
            let _timeStr2: string = NumModule_blxf.instance.getTimeStr2_blxf( _doubleRewardTime );
            UtilsModule_blxf.setText_blxf( this.rewardTimeNode, _timeStr2 );
        }
    }

    /** 更新福贴按钮父节点 */
    updateCoupletBtn_blxf () {
        let _index = PublicModule_blxf.isAllShopTarget ? 1 : 0;
        let _parentNode = PublicModule_blxf.coupletParentList[ _index ];
        if ( !_parentNode ) return;

        this.coupletNode.parent = _parentNode;
    }

    /** 检测触发装饰解锁引导 */
    onCheckTriggeGuidanceBuild_blxf () {
        if ( this.newBuildTips.opacity != 255 ) return;
        if ( PublicModule_blxf.gamePlayPageId != 2 ) return;

        PageManager_blxf.instance.loadGuidance_blxf( 3 );
    }

    /** 检测触发房间装饰解锁引导 */
    onCheckTriggeGuidanceRoomBuild_blxf () {
        if ( this.newRoomBuildTips.opacity != 255 ) return;
        if ( PublicModule_blxf.gamePlayPageId != 3 ) return;

        PageManager_blxf.instance.loadGuidance_blxf( 4 );
    }

    /** 上报自定义事件 */
    onReportEvent_blxf () {
        // let _isNewUser: boolean = UtilsModule_blxf.onCheckNewUser_blxf();
        // let _userId: number = _isNewUser ? 1 : 2;
        // UtilsModule_blxf.onReportEvent_blxf( 2, 9001, false, { "user": `${_userId}` } );
    }
}
